<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>权限管理系统</title>
<jsp:include page="/views/include.jsp"></jsp:include>
<script type="text/javascript">
    var contextPath = '<%=request.getContextPath()%>';
	$.parser.onComplete = function() {
		$('body').css('visibility', 'visible');
		setTimeout(function() {
			$('#loading-mask').remove();
		}, 50);
	};
	$(function() {
		$(window).resize(function() {
			$('#mainlayout').layout('resize');
		});
		
		$('#tree').tree({
			url : "<c:url value='/etl/dataSourceloadTree.tg' />",
			onClick: function(node) {
				var queryParams = $('#dt-table').datagrid('options').queryParams;
				queryParams.treeId = node.id;
				queryParams.shopId = 1;
				queryParams.attributes = node.attributes;
				$('#dt-table').datagrid('loadData', {total:0,rows:[]});
				$('#dt-table').datagrid("reload");
			}
		});
	
		$('#dt-table').datagrid({
			onDblClickRow:function(rowIndex, rowData){
				$('#property_update_form')[0].reset();
				$('#property_update_form').formid('loadit',rowData);
				$('#property_update_dialog').dialog('setTitle','修改表字段信息 -- ' + rowData.table_name).dialog('open');	
			}
		});
		
	});
	
	
	function updateItem2(){
    	var row = $('#dt-table').datagrid('getSelected');
		if (row) {
			$('#property_update_form')[0].reset();
			$('#property_update_form').formid('loadit',row);
			$('#property_update_dialog').dialog('setTitle','修改表字段信息 -- ' + row.table_name).dialog('open');	
		} else {
			$.messager.show({
				title:'注意',
				msg:'请先选择数据，再进行修改。'
			});
		}
    }
	
	function updateItem() {
		$('#property_update_form').form('submit', {
			url:'<c:url value="/etl/property_update.tg"/>',
			onSubmit:function() { return true; },
			dataType:"json",
			success:function(result) {
				var data = eval("(" + result + ")");
				if(data.success) {
					$.messager.show({
						title		:	'提示',
						msg			:	data.message,
						showType	:	'slide'
					});
					$('#property_update_dialog').dialog('close');
					$('#dt-table').datagrid('loadData', {total:0,rows:[]});
					$('#dt-table').datagrid("reload");
				} else {
					$.messager.alert('警告','操作失败！','error');
				}
			}
		});
	}
</script>
</head>
<body style="margin: 0; padding: 0; height: 100%; overflow: hidden; background: #F2FBFF">
	<div id="mainlayout" class="easyui-layout" fit="true">
		<div region="west" border="false" style="border-right: 1px solid #92B7D0; width: 300px; padding: 5px;">
			<div id="allTrees">
			    <ul id="tree" class="easyui-tree"></ul>
			</div>
		</div>
		<div id="dd-table" region="center" border="false">
			<div class="toolbar">
				<table cellpadding="0" cellspacing="0">
					<tr>
						<td>
        					<a id="handle3" href="javascript:updateItem2()" class="easyui-linkbutton" iconCls="icon-edit" plain="true" >修改</a>
						</td>
					</tr>
				</table>
			</div>
		 
			<table id="dt-table" class="easyui-datagrid" url="<c:url value='/etl/dataSourcelistAll.tg'/>" fit="true" border="false" pagination="true" striped="true" fitColumns="true" singleSelect="true" rownumbers="true">
				<thead>
					<th field="property_name" width="80">名称</th>
					<th field="table_name" width="100">表名</th>
					<th field="property_alias" width="60" >别名</th>
					<th field="property_desc" width="60" >描述</th>
					<th field="property_defaultValue" width="60" >默认值</th>
				</thead>
			</table>
		</div>
		
	</div>
	
	
	<!-- 修改数据源 start -->
		<div id="property_update_dialog" class="easyui-dialog" closed="true" modal="true" buttons="#property_update_dialog-buttons">
			<form id="property_update_form" method="post">
				<input type="hidden" id="property_id" name="property_id">
				<div style="padding:20px">
					<table cellpadding="0" cellspacing="0" class="form-table">
						<tr>
							<td>字段名称：</td>
							<td><input id="property_name" class="easyui-validatebox" style="width:250px" disabled="true" /></td>
						</tr>
						<tr>
							<td>别名：</td>
							<td><input id="property_alias" name="property_alias" class="easyui-validatebox" style="width:250px" /></td>
						</tr>
						<tr>
							<td>默认值：</td>
							<td><input id="property_defaultValue" name="property_defaultValue" class="easyui-validatebox" style="width:250px" /></td>
						</tr>
						<tr>
							<td>备注：</td>
							<td><textarea id="property_desc" name="property_desc" class="easyui-validatebox" style="height:100px;width:250px;"></textarea></td>
						</tr>
					</table>
				</div>
			</form>
			<div id="property_update_dialog-buttons" style="text-align: right;">
				<a href="#" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#property_update_dialog').dialog('close')">关闭</a>
				<a href="#" class="easyui-linkbutton" iconCls="icon-save" onclick="updateItem()">保存</a> 
			</div>
		</div>
		<!-- 修改数据源 end -->
</body>
</html>